package com.fingard.dsp.bank.directbank.lcbip01;

import java.math.BigDecimal;
import java.sql.Connection;
import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import com.fingard.FGBiz;
import com.fingard.constant.Format;
import com.fingard.db.JDBCHelper;
import com.fingard.dsp.bank.directbank.bankInterface.IElecBillTrans;
import com.fingard.dsp.bank.reqrespobj.elecbilltrans.*;
import com.fingard.dsp.bank.reqrespobj.elecbilltrans.detail.*;
import com.fingard.text.StringHelper;
import com.fingard.util.DateHelper;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

/**
 * Created by F on 2018/9/18.
 */
public class LCBIP01ElecBillTrans extends LCBIP01Base implements IElecBillTrans {
    private static final String INSERTRECEIPT = "INSERT INTO REQSEQIDMAPPING(URID,BANKCODE,TRANSDATE,REQSEQID,BANKREQSEQID) values (?,?,?,?,?);";
    @Override
    public RetAtsB003BillRespSubmit D_B003_BillResp_Submit(ReqB003BillRespSubmit query) throws Exception {
//        BillSignSubmit
        RetAtsB003BillRespSubmit retAts = new RetAtsB003BillRespSubmit(query.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        while (query.readRecord()){
            RetAtsB003BillRespSubmitDetail detail = new RetAtsB003BillRespSubmitDetail();
            try {
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
                LCBIP01Header header = new LCBIP01Header();
                header.TuxName = "BillSignSubmit";
                header.ReqSeqNo =query.detail.reqSeqID;
                writeCommonHeader(xmlTextWriter,header);
                xmlTextWriter.writeElementString("ReqReserved1","",true);
                xmlTextWriter.writeElementString("ReqReserved2","",true);
                xmlTextWriter.writeElementString("ReqReserved3","",true);
                xmlTextWriter.writeElementString("ReqReserved4","",true);
                xmlTextWriter.writeEndElement();
                xmlTextWriter.writeStartElement("body");
//                企业编号	CustCode	成员单位在内部ERP系统的客户编号
                xmlTextWriter.writeElementString("CustCode",bankFront.org);
//                机构名称	OrgName	Y	默认写死：兵器装备集团财务有限责任公司
                xmlTextWriter.writeElementString("OrgName","兵器装备集团财务有限责任公司");
//                机构号	OrgNo	Y	写死：99
                xmlTextWriter.writeElementString("OrgNo","99");
//                签收回复信息	BillSignInfos	Y	可多条，可单条，本字段具体明细字段见【票据签收结果回复明细表】
                xmlTextWriter.writeStartElement("BillSignInfos");
                xmlTextWriter.writeStartElement("BillSignInfo");
//                BznsType	CHAR	业务类型	M	业务类型
                //    应答类型 1-承兑应答 2-收票应答 3-背书转让应答 4-回购式贴现赎回应答 5-质押解除应答 6-提示付款应答 7-保证应答 8-同意清偿应
                String bznsType;
                switch (Integer.valueOf(query.detail.respType)){
                    case 2:bznsType ="03";break;//收票
                    case 1:bznsType ="02";break;//承兑
                    case 3:bznsType ="10";break;//背书
                    case 5:bznsType ="19";break;//质解
                    case 7:bznsType ="17";break;//保证
                    case 4:bznsType ="12";break;//贴现赎回
                    case 8:bznsType ="23";break;//清偿
                    default:throw new Exception("未知的业务类型："+query.detail.respType);
                }
                xmlTextWriter.writeElementString("BznsType",bznsType);
//                TosignNm	CHAR	单据编号	M	单据编号
                xmlTextWriter.writeElementString("TosignNm",query.detail.busiNo);
//                PayoffResult	CHAR	回复结果	M	00：同意，01：拒绝
                String payoffResult;
                if("1".equals(query.detail.respFlag)){
                    payoffResult = "00";
                }else {
                    payoffResult = "01";
                }
                xmlTextWriter.writeElementString("PayoffResult",payoffResult);
                //                ReplyOrRefuseInfo	CHAR	回复信息	M	回复信息
                if(StringHelper.isNullOrEmpty(query.detail.memo)&&"00".equals(payoffResult)) {
                    xmlTextWriter.writeElementString("ReplyOrRefuseInfo", "同意签收");
                }else if(StringHelper.isNullOrEmpty(query.detail.memo)&&"01".equals(payoffResult)) {
                    xmlTextWriter.writeElementString("ReplyOrRefuseInfo", "拒绝签收");
                }else {
                    xmlTextWriter.writeElementString("ReplyOrRefuseInfo", query.detail.memo);
                }
                xmlTextWriter.writeEndElement();
                xmlTextWriter.writeEndElement();
//                备用字段1	ReqReserved1 reqReserved1
                xmlTextWriter.writeElementString("ReqReserved1","",true);
//                备用字段2	ReqReserved2 reqReserved2
                xmlTextWriter.writeElementString("ReqReserved2","",true);
//                备用字段3	ReqReserved3 reqReserved3
                xmlTextWriter.writeElementString("ReqReserved3","",true);
//                备用字段4	ReqReserved4 reqReserved4
                xmlTextWriter.writeElementString("ReqReserved4","",true);
                xmlTextWriter.writeEndDocument();
                String[] result =sendToBank(xmlTextWriter.toXmlString());
                if(result[0].length()==0) {
                    StringBuilder tmpsbMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1],tmpsbMsg);
                    if(tmpbkReader!=null){
                        String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                        String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                        if("0".equals(returnCode)){
                            detail.respCode ="0";
                            detail.respInfo = tmpbkReader.getFirstText("/lcbank/body/BillSignSbRespParam/ErrorInfo");
                            detail.transState = tmpbkReader.getFirstText("/lcbank/body/BillSignSbRespParam/Result");
                            detail.payInfoCode = detail.transState;
                            String outid = tmpbkReader.getFirstText("/lcbank/body/EndorseId");
                            String uuid = UUID.randomUUID().toString().replaceAll("-","");
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,Format.Date8Format.format(new Date()),query.detail.reqSeqID,outid});
                        }else {
                            detail.respCode="-1";
                            detail.respInfo = returnInfo;
                        }
                    }else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpsbMsg.toString();
                    }
                }else{
                    detail.respCode = "-1";
                    detail.respInfo = result[1];
                }
            }catch (Exception ex){
                ex.printStackTrace();
                detail.respCode = "-1";
                detail.respInfo =ex.getMessage();
            }finally {
                conn.close();
            }
            retAts.writeDetail(detail);
        }
        retAts.writeEnd();
        return retAts;
    }
    //出票登记
    @Override
    public RetAtsB101BillApplySubmit D_B101_BillResp_Submit(ReqB101BillApplySubmit query) throws Exception {
        RetAtsB101BillApplySubmit retAts = new RetAtsB101BillApplySubmit(query.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        while (query.readRecord()){
            RetAtsB101BillApplySubmitDetail detail = new RetAtsB101BillApplySubmitDetail();
            try {
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
                LCBIP01Header header = new LCBIP01Header();
                header.TuxName = "BillApplySubmit";
                header.ReqSeqNo =query.detail.reqSeqID;
                writeCommonHeader(xmlTextWriter,header);
                xmlTextWriter.writeElementString("ReqReserved1","",true);
                xmlTextWriter.writeElementString("ReqReserved2","",true);
                xmlTextWriter.writeElementString("ReqReserved3","",true);
                xmlTextWriter.writeElementString("ReqReserved4","",true);
                xmlTextWriter.writeEndElement();
                xmlTextWriter.writeStartElement("body");
                //        CustCode	CHAR	企业编号	Y	集团签约模式：企业直连对接系统内部编号/财务公司编号
                xmlTextWriter.writeElementString("CustCode",bankFront.org);
//        非集团签约模式：财务公司编号
//        OrgName	CHAR	机构名称	Y	默认写死：兵器装备集团财务有限责任公司
                xmlTextWriter.writeElementString("OrgName","兵器装备集团财务有限责任公司");
//        OrgNo	CHAR	机构号	Y	写死：99
                xmlTextWriter.writeElementString("OrgNo","99");
//        BillType	CHAR	票据种类	Y	票据种类:
                xmlTextWriter.writeElementString("BillType",query.detail.billType);
//        银行承兑汇票：“1”、
//        商业承兑汇票：“2”
//        OuterBill	CHAR	出票人名称	Y	用户当前企业名称
                xmlTextWriter.writeElementString("OuterBill",query.detail.drawName);
//        BusinessType	CHAR	业务标志	Y	默认写死：传统：12 批售：01
                xmlTextWriter.writeElementString("BusinessType","12");
//        BillStart	CHAR	合同起始日	Y	合同起始日：yyyyMMdd
                xmlTextWriter.writeElementString("BillStart",query.detail.issDate.substring(0,10).replaceAll("-",""));
//        BillEnd	CHAR	合同到期日	Y	合同到期日：yyyyMMdd
                xmlTextWriter.writeElementString("BillEnd",query.detail.dueDate.substring(0,10).replaceAll("-",""));
//        OpenBillType	CHAR	开票方式	Y	额度开票：1
                xmlTextWriter.writeElementString("OpenBillType","5");
//        全额保证金开票:2
//        质押开票:3
//        汽车金融：4
//        其他5
//        IsOccute	CHAR	是否占用授信	Y	是：1
                String creditBreedAmt = query.detail.useCreditAmount;
                if(StringHelper.hasAnyChar(creditBreedAmt)&&Double.valueOf(creditBreedAmt)>0) {
                    xmlTextWriter.writeElementString("IsOccute", "1");
//                    CreditBreedNo	CHAR	占用授信品种编号	N	当是否占用授信额度为是时，必填
//                    Map<String,String> creditBreedNo = queryBillCredit();
//                    if(creditBreedNo.keySet().size()!=0) {
//                        if(Double.valueOf(creditBreedAmt)<=Double.valueOf(creditBreedNo.get("AvailableBal"))) {
                            String creditBreedNo =  getBankConfig().getValueAsString("CreditBreedNo");
                            xmlTextWriter.writeElementString("CreditBreedNo",creditBreedNo);
                            xmlTextWriter.writeElementString("CreditBreedAmt",creditBreedAmt);
//                        }else{
//                            throw new Exception("授信额度不足");
//                        }
//                    }else{
//                        throw new Exception("查询授信合同异常");
//                    }
                }else {
                    xmlTextWriter.writeElementString("IsOccute", "0");
                    xmlTextWriter.writeElementString("CreditBreedNo","");
                    //        CreditBreedAmt	CHAR	占用授信金额	Y	不占用为0.00
                    xmlTextWriter.writeElementString("CreditBreedAmt","0.00");
                }
//        MarginAcct	CHAR	保证金账户	Y	企业的保证金账户
                xmlTextWriter.writeElementString("MarginAcct",query.detail.marginAcct);
//        CommissionChargeAcct	CHAR	手续费扣收账户	Y	企业的结算户
                xmlTextWriter.writeElementString("CommissionChargeAcct",query.detail.commissionChargeAcct);
//        Remark	CHAR	备注	N
                xmlTextWriter.writeElementString("Remark",query.detail.memo);
//        OpenApplyNo	CHAR	开票申请内码	Y
                xmlTextWriter.writeElementString("OpenApplyNo","",true);
//        BillDetailAddReqParams	CHAR[]	票据明细参数上送数组		可多条，可单条，详细信息见票据明细报存-上送信息
                xmlTextWriter.writeStartElement("BillDetailAddReqParams");
                xmlTextWriter.writeStartElement("BillDetailAddReqParam");
//                PjyfkcNm	CHAR	票据内码	O	如为空时为保存信息 如不为空时为修改信息
                xmlTextWriter.writeElementString("PjyfkcNm","",true);
//                BillMedium	CHAR	票据介质	M	电票 1 写死
                xmlTextWriter.writeElementString("BillMedium","1");
//                OuterNo	CHAR	出票人编号	M	用户当前企业编号
                xmlTextWriter.writeElementString("OuterNo",bankFront.org);
//                OuterAcct	CHAR	出票人账号	M	出票人信息 反显客户选择的账户
                xmlTextWriter.writeElementString("OuterAcct",query.detail.drawAct);
//                OuterBankNo	CHAR	出票人开户行行号	M	出票人信息 写死：99
                xmlTextWriter.writeElementString("OuterBankNo","99");
//                OuterBankName	CHAR	出票人开户行名称	M	出票人信息 默认写死：兵器装备集团财务有限责任公司
                xmlTextWriter.writeElementString("OuterBankName","兵器装备集团财务有限责任公司");
//                InnerName	CHAR	收票人名称	M	收票人信息
                xmlTextWriter.writeElementString("InnerName",query.detail.payeeName);
//                InnerNo	CHAR	收票人编号	O
                xmlTextWriter.writeElementString("InnerNo","",true);
//                InnerAcct	CHAR	收票人账号	M	收票人信息
                xmlTextWriter.writeElementString("InnerAcct",query.detail.payeeAct);
//                InnerBankNo	CHAR	收票人开户行行号	M	收票人信息
                xmlTextWriter.writeElementString("InnerBankNo",query.detail.payeeBnkCode);
//                InnerBankName	CHAR	收票人开户行名称	M	收票人信息
                xmlTextWriter.writeElementString("InnerBankName",query.detail.payeeBnkName);
//                BillDate	CHAR	开票日期	M	开票日期：yyyyMMdd
                Date billDate = Format.DateTime21Format.parse(query.detail.issDate);
                xmlTextWriter.writeElementString("BillDate",Format.Date8Format.format(billDate));
                Date dueDate = Format.DateTime21Format.parse(query.detail.dueDate);
//                EndDate	CHAR	到期日期	M	到期日期：yyyyMMdd
                xmlTextWriter.writeElementString("EndDate",Format.Date8Format.format(dueDate));
//                BillAmt	CHAR	票面金额	M
                xmlTextWriter.writeElementString("BillAmt",query.detail.billAmt);
//                AccepterName	CHAR	承兑人名称	M	默认写死：兵器装备集团财务有限责任公司
                xmlTextWriter.writeElementString("AccepterName","兵器装备集团财务有限责任公司");
//                AccepterNo	CHAR	承兑人编号	M	写死：99
                xmlTextWriter.writeElementString("AccepterNo","99");
//                AccepterAcct	CHAR	承兑人账户	M	写死：0
                xmlTextWriter.writeElementString("AccepterAcct","0");
//                IsTrans	CHAR	是否转让	M	可再转让：EM00 不得转让：EM01
                String isTrans;
                if("1".equals(query.detail.transFlag)){
                    isTrans = "EM00";
                }else{
                    isTrans = "EM01";
                }
                xmlTextWriter.writeElementString("IsTrans",isTrans);
                xmlTextWriter.writeEndElement();
                xmlTextWriter.writeEndElement();
//        ReqReserved1 CHAR	备用字段1		 ReqReserved1
                xmlTextWriter.writeElementString("ReqReserved1","",true);
//                ReqReserved2 CHAR	备用字段2		ReqReserved2
                xmlTextWriter.writeElementString("ReqReserved2","",true);
//                ReqReserved3 CHAR	备用字段3		ReqReserved3
                xmlTextWriter.writeElementString("ReqReserved3","",true);
//                ReqReserved4 CHAR	备用字段4		ReqReserved4
                xmlTextWriter.writeElementString("ReqReserved4","",true);
//
                xmlTextWriter.writeEndDocument();
                String[] result =sendToBank(xmlTextWriter.toXmlString());
//                String[] result = new String[]{"","<?xml version=\"1.0\" encoding=\"UTF-8\"?><lcbank><head><BankNo>50</BankNo><TuxName>BillApplySubmit</TuxName><ReqSeqNo>RN000015O2</ReqSeqNo><RespCode>1</RespCode><RespDate>20190129</RespDate><RespTime>163345</RespTime><RespInfo>授信额度不足，不能提交</RespInfo><RecordNum>1</RecordNum></head><body><BillApplyAddRespParam><Result>01</Result><PjyfkcNm><String>KP190129006</String></PjyfkcNm><ReqReserved1 /><ReqReserved2 /><ReqReserved3 /><ReqReserved4 /><ErrorInfo>授信额度不足，不能提交</ErrorInfo><BillApplyCode /></BillApplyAddRespParam></body></lcbank>"};
                if(result[0].length()==0) {
                    StringBuilder tmpsbMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1],tmpsbMsg);
                    if(tmpbkReader!=null){
                        String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                        String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                        if("0".equals(returnCode)){
                            detail.respCode ="0";
                            detail.respInfo = tmpbkReader.getFirstText("/lcbank/body/BillApplyAddRespParam/ErrorInfo");
                            detail.transState = tmpbkReader.getFirstText("/lcbank/body/BillApplyAddRespParam/Result");
                            detail.payInfoCode = detail.transState;
                            String outid = tmpbkReader.getFirstText("/lcbank/body/BillApplyAddRespParam/PjyfkcNm/String");
                            String uuid = UUID.randomUUID().toString().replaceAll("-","");
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,Format.Date8Format.format(new Date()),query.detail.reqSeqID,outid});
                        }else if("1".equals(returnCode)){
                            detail.respCode ="0";
                            detail.respInfo = tmpbkReader.getFirstText("/lcbank/body/BillApplyAddRespParam/ErrorInfo");
                            detail.transState = "1+"+tmpbkReader.getFirstText("/lcbank/body/BillApplyAddRespParam/Result");
                            detail.payInfoCode = detail.transState;
                        }else {
                            detail.respCode="-1";
                            detail.respInfo = returnInfo;
                        }
                    }else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpsbMsg.toString();
                    }
                }else{
                    detail.respCode = "-1";
                    detail.respInfo = result[1];
                }
            }catch (Exception ex){
                ex.printStackTrace();
                detail.respCode = "-1";
                detail.respInfo =ex.getMessage();
            }finally {
                conn.close();
            }
            retAts.writeDetail(detail);
        }
        retAts.writeEnd();
        return retAts;
    }

    private Map<String,String> queryBillCredit()throws Exception{
        Map billCredit = new HashMap<String,String>();
        XmlTextWriter xmlTextWriter = new XmlTextWriter();
        LCBIP01Header header = new LCBIP01Header();
        header.TuxName = "QueryBillCredit";
        header.ReqSeqNo =getQryTransID();
        writeCommonHeader(xmlTextWriter,header);
        xmlTextWriter.writeElementString("ReqReserved1","",true);
        xmlTextWriter.writeElementString("ReqReserved2","",true);
        xmlTextWriter.writeElementString("ReqReserved3","",true);
        xmlTextWriter.writeElementString("ReqReserved4","",true);
        xmlTextWriter.writeEndElement();
        xmlTextWriter.writeStartElement("body");
//        CustCode	CHAR	企业编号
        xmlTextWriter.writeElementString("CustCode",bankFront.org);
//        PrdCode	CHAR	业务子类型	N
        xmlTextWriter.writeElementString("PrdCode","",true);
//        Pjxs CHAR	票据形式	Y
        xmlTextWriter.writeElementString("Pjxs","1",true);
//        ReqReserved1 CHAR	备用字段1
        xmlTextWriter.writeElementString("ReqReserved1","",true);
//        ReqReserved2 CHAR	备用字段2
        xmlTextWriter.writeElementString("ReqReserved2","",true);
//        ReqReserved3 CHAR	备用字段3
        xmlTextWriter.writeElementString("ReqReserved3","",true);
//        ReqReserved4 CHAR	备用字段4
        xmlTextWriter.writeElementString("ReqReserved4","",true);
        xmlTextWriter.writeEndDocument();
        String[] result =sendToBank(xmlTextWriter.toXmlString());
        if(result[0].length()==0) {
            StringBuilder tmpsbMsg = new StringBuilder();
            XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1],tmpsbMsg);
            if(tmpbkReader!=null){
                String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                if("0".equals(returnCode)){
                   if(tmpbkReader.read("/lcbank/Nbody/BillCreditQueryRespParam")){
                       String creditNo = tmpbkReader.readedXElement.getSingleText("CreditNo");
                       billCredit.put("CreditNo",creditNo);
                       String availableBal = tmpbkReader.readedXElement.getSingleText("AvailableBal");
                       billCredit.put("AvailableBal",availableBal);
                   }
                }else {
                    throw new Exception(returnInfo);
                }
            }else {
                throw new Exception(tmpsbMsg.toString());
            }
        }else{
            throw new Exception(result[1]);
        }
        return billCredit;
    }

    //出票承兑
    @Override
    public RetAtsB102BillAccpSubmit D_B102_BillResp_Submit(ReqB102BillAccpSubmit query) throws Exception {
        return null;
    }
//撤票
    @Override
    public RetAtsB103BillRetSubmit D_B103_BillResp_Submit(ReqB103BillRetSubmit query) throws Exception {
        RetAtsB103BillRetSubmit retAts = new RetAtsB103BillRetSubmit(query.reqHeader);
        retAts.writeStart();
        while (query.readRecord()){
            RetAtsB103BillRetSubmitDetail detail = new RetAtsB103BillRetSubmitDetail();
            try {
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
                LCBIP01Header header = new LCBIP01Header();
                header.TuxName = "BillCancelSubmit";
                header.ReqSeqNo =query.detail.reqSeqID;
                writeCommonHeader(xmlTextWriter,header);
                xmlTextWriter.writeElementString("ReqReserved1","",true);
                xmlTextWriter.writeElementString("ReqReserved2","",true);
                xmlTextWriter.writeElementString("ReqReserved3","",true);
                xmlTextWriter.writeElementString("ReqReserved4","",true);
                xmlTextWriter.writeEndElement();
                xmlTextWriter.writeStartElement("body");
//                企业编号	CustCode	成员单位在内部ERP系统的客户编号
                xmlTextWriter.writeElementString("CustCode",bankFront.org);
//                票据编号	BillCodes	Y	进行撤票申请的30位票据编号，可单张可多张票据，多张票据，票据编号以“|”分隔
                xmlTextWriter.writeElementString("BillCodes",query.detail.billNo);
//                备注	Remark
                xmlTextWriter.writeElementString("Remark",query.detail.memo);
//                备用字段1	ReqReserved1 reqReserved1
                xmlTextWriter.writeElementString("ReqReserved1","",true);
//                备用字段2	ReqReserved2 reqReserved2
                xmlTextWriter.writeElementString("ReqReserved2","",true);
//                备用字段3	ReqReserved3 reqReserved3
                xmlTextWriter.writeElementString("ReqReserved3","",true);
//                备用字段4	ReqReserved4 reqReserved4
                xmlTextWriter.writeElementString("ReqReserved4","",true);
                xmlTextWriter.writeEndDocument();
                String[] result =sendToBank(xmlTextWriter.toXmlString());
                if(result[0].length()==0) {
                    StringBuilder tmpsbMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1],tmpsbMsg);
                    if(tmpbkReader!=null){
                        String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                        String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                        if("0".equals(returnCode)){
                            detail.respCode ="0";
                            detail.respInfo = tmpbkReader.getFirstText("/lcbank/body/BillCancelSubmitRespParam/ErrorInfo");
                            detail.transState = tmpbkReader.getFirstText("/lcbank/body/BillCancelSubmitRespParam/Result");
                            detail.payInfoCode = detail.transState;
//                            detail.reqSeqID = tmpbkReader.getFirstText("/lcbank/body/EndorseId");
//                            String outid = tmpbkReader.getFirstText("/lcbank/body/BillApplyAddRespParam/billApplyCode");
//                            String uuid = UUID.randomUUID().toString().replaceAll("-","");
//                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,Format.Date8Format.format(new Date()),query.detail.reqSeqID,outid});
//
                        }else {
                            detail.respCode="-1";
                            detail.respInfo = returnInfo;
                        }
                    }else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpsbMsg.toString();
                    }
                }else{
                    detail.respCode = "-1";
                    detail.respInfo = result[1];
                }
            }catch (Exception ex){
                ex.printStackTrace();
                detail.respCode = "-1";
                detail.respInfo =ex.getMessage();
            }
            retAts.writeDetail(detail);
        }
        retAts.writeEnd();
        return retAts;
    }
//提示收票
    @Override
    public RetAtsB104BillReceSubmit D_B104_BillResp_Submit(ReqB104BillReceSubmit query) throws Exception {
        return null;
    }
//背书
    @Override
    public RetAtsB105BillEndoSubmit D_B105_BillResp_Submit(ReqB105BillEndoSubmit query) throws Exception {
        RetAtsB105BillEndoSubmit retAts = new RetAtsB105BillEndoSubmit(query.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        while (query.readRecord()){
            RetAtsB105BillEndoSubmitDetail detail = new RetAtsB105BillEndoSubmitDetail();
            try {
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
                LCBIP01Header header = new LCBIP01Header();
                header.TuxName = "BillEndorseApply";
                header.ReqSeqNo =query.detail.reqSeqID;
                writeCommonHeader(xmlTextWriter,header);
                xmlTextWriter.writeElementString("ReqReserved1","",true);
                xmlTextWriter.writeElementString("ReqReserved2","",true);
                xmlTextWriter.writeElementString("ReqReserved3","",true);
                xmlTextWriter.writeElementString("ReqReserved4","",true);
                xmlTextWriter.writeEndElement();
                xmlTextWriter.writeStartElement("body");
//                企业编号	CustCode	成员单位在内部ERP系统的客户编号
                xmlTextWriter.writeElementString("CustCode",bankFront.org);
//                机构名称	OrgName	默认写死：兵器装备集团财务有限责任公司
                xmlTextWriter.writeElementString("OrgName","兵器装备集团财务有限责任公司");
//                机构号	OrgNo	写死：99
                xmlTextWriter.writeElementString("OrgNo","99");
//                票据种类	BillType	票据种类:银行承兑汇票：“1”、商业承兑汇票：“2”
                xmlTextWriter.writeElementString("BillType",query.detail.billType);
//                背书人账户	CustBankAcc	背书申请企业的结算账户
                xmlTextWriter.writeElementString("CustBankAcc",query.detail.actNum);
//                OppCustName	be背书人名称
                xmlTextWriter.writeElementString("OppCustName",query.detail.receName);
//                被背书人账户 OppBankAcc
                xmlTextWriter.writeElementString("OppBankAcc",query.detail.receAct);
//                被背书人开户行名称 OppBankName
                xmlTextWriter.writeElementString("OppBankName",query.detail.receBnkName);
//                被背书人开户行号	OppBankNo
                xmlTextWriter.writeElementString("OppBankNo",query.detail.receBnkCode);
//                背书金额 Money
                xmlTextWriter.writeElementString("Money",query.detail.billAmt);
//                可转让标注 TransferFlag 可再转让：EM00 不得转让：EM01
                String transferFlag = query.detail.transFlag;
                if("1".equals(transferFlag)){
                    transferFlag = "EM00";
                }else{
                    transferFlag = "EM01";
                }
                xmlTextWriter.writeElementString("TransferFlag",transferFlag);
//                背书日期 BznsDate 默认当前账务日期
                xmlTextWriter.writeElementString("BznsDate", Format.Date8Format.format(new Date()));
//                库存票据编号	BillCodes	需要背书的库存票据的编号，从收票信息中查询到的30位票据编号，可以以数组方式传递单张或多张票据
                xmlTextWriter.writeElementString("BillCodes",query.detail.billNo);
//                备注	Remark
                xmlTextWriter.writeElementString("Remark",query.detail.memo);
//                备用字段1	ReqReserved1 reqReserved1
                xmlTextWriter.writeElementString("ReqReserved1","",true);
//                备用字段2	ReqReserved2 reqReserved2
                xmlTextWriter.writeElementString("ReqReserved2","",true);
//                备用字段3	ReqReserved3 reqReserved3
                xmlTextWriter.writeElementString("ReqReserved3","",true);
//                备用字段4	ReqReserved4 reqReserved4
                xmlTextWriter.writeElementString("ReqReserved4","",true);
                xmlTextWriter.writeEndDocument();
                String[] result =sendToBank(xmlTextWriter.toXmlString());
                if(result[0].length()==0) {
                    StringBuilder tmpsbMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1],tmpsbMsg);
                    if(tmpbkReader!=null){
                        String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                        String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                        if("0".equals(returnCode)){
                            detail.respCode ="0";
                            detail.respInfo = tmpbkReader.getFirstText("/lcbank/body/BillEndosAddRespParam/ErrorInfo");
                            detail.transState = tmpbkReader.getFirstText("/lcbank/body/BillEndosAddRespParam/Result");
                            detail.payInfoCode = detail.transState;
                            String outid = tmpbkReader.getFirstText("/lcbank/body/BillEndosAddRespParam/EndorseId");
                            String uuid = UUID.randomUUID().toString().replaceAll("-","");
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,Format.Date8Format.format(new Date()),query.detail.reqSeqID,outid});

                        }else {
                            detail.respCode="-1";
                            detail.respInfo = returnInfo;
                        }
                    }else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpsbMsg.toString();
                    }
                }else{
                    detail.respCode = "-1";
                    detail.respInfo = result[1];
                }
            }catch (Exception ex){
                ex.printStackTrace();
                detail.respCode = "-1";
                detail.respInfo =ex.getMessage();
            }finally {
                conn.close();
            }
            retAts.writeDetail(detail);
        }
        retAts.writeEnd();
        return retAts;
    }
//贴现
    @Override
    public RetAtsB106BillDiscSubmit D_B106_BillResp_Submit(ReqB106BillDiscSubmit query) throws Exception {
        RetAtsB106BillDiscSubmit retAts = new RetAtsB106BillDiscSubmit(query.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        while (query.readRecord()){
            RetAtsB106BillDiscSubmitDetail detail = new RetAtsB106BillDiscSubmitDetail();
            try {
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
                LCBIP01Header header = new LCBIP01Header();
                header.TuxName = "BillDiscountApply";
                header.ReqSeqNo =query.detail.reqSeqID;
                writeCommonHeader(xmlTextWriter,header);
                xmlTextWriter.writeElementString("ReqReserved1","",true);
                xmlTextWriter.writeElementString("ReqReserved2","",true);
                xmlTextWriter.writeElementString("ReqReserved3","",true);
                xmlTextWriter.writeElementString("ReqReserved4","",true);
                xmlTextWriter.writeEndElement();
                xmlTextWriter.writeStartElement("body");
//                企业编号	CustCode	成员单位在内部ERP系统的客户编号
                xmlTextWriter.writeElementString("CustCode",bankFront.org);
//                GatheringAcct	CHAR	收款账户	Y	企业的结算账户
                xmlTextWriter.writeElementString("GatheringAcct",query.detail.actedAct);
//                PayInterstAcct	CHAR	付息账户	Y	企业的结算账户
                xmlTextWriter.writeElementString("PayInterstAcct",query.detail.actedAct);
//                AproposBankName	CHAR	贴入行名称	Y
                xmlTextWriter.writeElementString("AproposBankName",query.detail.receBnkName);
//                AproposBankNo	CHAR	贴入行行号	Y
                xmlTextWriter.writeElementString("AproposBankNo",query.detail.receBnkCode);
//                AproposBankAcct	CHAR	贴入银行账户	Y
                xmlTextWriter.writeElementString("AproposBankAcct",query.detail.receAct);
//                BillType	CHAR	票据类型	N	银行承兑汇票：“1”、
                xmlTextWriter.writeElementString("BillType",query.detail.billType);
//                BillStatus	CHAR	票据状态	Y
                xmlTextWriter.writeElementString("BillStatus","02");
//                OpeStatus	CHAR	操作状态	Y 记账
                xmlTextWriter.writeElementString("OpeStatus","20");
//                BillMedium	CHAR	票据介质	N	票据介质：电子：“1”、纸质：“0”
                xmlTextWriter.writeElementString("BillMedium","1");
//                DiscountDate	CHAR	贴现日期	Y	贴现日期：yyyyMMdd
                xmlTextWriter.writeElementString("DiscountDate", Format.Date8Format.format(new Date()));
//                DiscountType	CHAR	贴现方式	Y	贴现方式：0： 卖断 1： 回购
                String discountType;
                if("1".equals(query.detail.discType)){
                    discountType = "0";
                }else{
                    discountType ="1";
                }
                xmlTextWriter.writeElementString("DiscountType",discountType);
//                DiscountInterestRate CHAR	贴现利率%(年)	Y
                xmlTextWriter.writeElementString("DiscountInterestRate",query.detail.discRate);
//                ClearingType	CHAR	清算方式	N	贴现方式为卖断时必输   清算方式：写死线下清算  线下清算:SM01 线上清算:SM00
                if("1".equals(query.detail.payType)) {
//                    xmlTextWriter.writeElementString("ClearingType", "SM00");
                    throw new Exception("暂不支持线上清算");
                }else{
                    xmlTextWriter.writeElementString("ClearingType", "SM01");
                }

                if("1".equals(discountType)){
//                    RepoInterestRate CHAR	回购利率%(年)	N	贴现方式为回购时必输
                    xmlTextWriter.writeElementString("RepoInterestRate",query.detail.repRate);
//                    RepoAppointDate	CHAR	回购约定日期	N	贴现方式为回购时必输
                    xmlTextWriter.writeElementString("RepoAppointDate", DateHelper.convertD10toD8(query.detail.repOpenDate));
//                    RepoStratDate	CHAR	回购开始日期	N	贴现方式为回购时必输
                    if(DateHelper.compareDay(Format.Date10Format.parse(query.detail.repOpenDate),new Date())!=-1){
                        throw new Exception("回购起始日要大于贴现申请日期");
                    }
                    xmlTextWriter.writeElementString("RepoStratDate",DateHelper.convertD10toD8(query.detail.repOpenDate));
//                    RepoEndDate	CHAR	回购截至日期	N	贴现方式为回购时必输
                    xmlTextWriter.writeElementString("RepoEndDate",DateHelper.convertD10toD8(query.detail.repDueDate));
                }
//                PayInterestType CHAR	付息方式	Y	付息方式：写死卖方付息 卖方付息：1
                xmlTextWriter.writeElementString("PayInterestType","1");
//                PayInterest	CHAR	卖方付息比率%	Y	写死 100
                xmlTextWriter.writeElementString("PayInterest","100");
//                BillMoney	CHAR	票面总额	Y
                xmlTextWriter.writeElementString("BillMoney",query.detail.billAmt);
//                InterestMoney CHAR	利息总额	Y	票面金额 * 利率
                BigDecimal total = new BigDecimal(query.detail.billAmt);
                BigDecimal interestMoney = new BigDecimal(query.detail.billAmt).multiply(new BigDecimal(query.detail.discRate));
                BigDecimal discountMoney = total.subtract(interestMoney);
                xmlTextWriter.writeElementString("InterestMoney",interestMoney.setScale(2,BigDecimal.ROUND_HALF_UP).toString());
//                RealDiscountMonery	CHAR	实际贴现总额	Y	票面总额 - 利息总额
                xmlTextWriter.writeElementString("RealDiscountMonery",discountMoney.setScale(2,BigDecimal.ROUND_HALF_UP).toString());
//                IsTrans	CHAR	是否可转让	Y	可再转让：EM00 不得转让：EM01
                String isTrans;
                if("1".equals(query.detail.transFlag)){
                    isTrans = "EM00";
                }else {
                    isTrans ="EM01";
                }
                xmlTextWriter.writeElementString("IsTrans",isTrans);
//                Remark	CHAR	备注	N	备注
                xmlTextWriter.writeElementString("Remark",query.detail.memo);
//                ?<BillDetailReqParams>
                xmlTextWriter.writeStartElement("BillDetailReqParams");
//                ????????<BillDetailReqParam>
                xmlTextWriter.writeStartElement("BillDetailReqParam");
//                ????????????<BillCode>190710000025520180812000058245</BillCode>
                xmlTextWriter.writeElementString("BillCode",query.detail.billNo);
//                ????????????<BillAmt>2005</BillAmt>
                xmlTextWriter.writeElementString("BillAmt",query.detail.billAmt);
//                ????????????<DiscInstAmt>30.63</DiscInstAmt>
                xmlTextWriter.writeElementString("DiscInstAmt",discountMoney.setScale(2,BigDecimal.ROUND_HALF_UP).toString());
//                ????????????<DisDays>50</DisDays>
                Date end = Format.DateTime21Format.parse(query.detail.dueDate);
                double diffDate = DateHelper.getDifferDays(end,new Date());
                xmlTextWriter.writeElementString("DisDays",new BigDecimal(diffDate).setScale(0,BigDecimal.ROUND_UP).toString());
//                xmlTextWriter.writeElementString("DisDays","30");
//                ????????</BillDetailReqParam>
//                ????</BillDetailReqParams>
                xmlTextWriter.writeEndElement();
                xmlTextWriter.writeEndElement();
//                备用字段1	ReqReserved1 reqReserved1
                xmlTextWriter.writeElementString("ReqReserved1","",true);
//                备用字段2	ReqReserved2 reqReserved2
                xmlTextWriter.writeElementString("ReqReserved2","",true);
//                备用字段3	ReqReserved3 reqReserved3
                xmlTextWriter.writeElementString("ReqReserved3","",true);
//                备用字段4	ReqReserved4 reqReserved4
                xmlTextWriter.writeElementString("ReqReserved4","",true);
                xmlTextWriter.writeEndDocument();
                String[] result =sendToBank(xmlTextWriter.toXmlString());
                if(result[0].length()==0) {
                    StringBuilder tmpsbMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1],tmpsbMsg);
                    if(tmpbkReader!=null){
                        String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                        String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                        if("0".equals(returnCode)){
                            detail.respCode ="0";
                            detail.respInfo = tmpbkReader.getFirstText("/lcbank/body/BillDisAddRespParam/ErrorInfo");
                            detail.transState = tmpbkReader.getFirstText("/lcbank/body/BillDisAddRespParam/Result");
                            detail.payInfoCode = detail.transState;
                            String outid = tmpbkReader.getFirstText("/lcbank/body/BillApplyAddRespParam/EndorseId");
                            String uuid = UUID.randomUUID().toString().replaceAll("-","");
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,Format.Date8Format.format(new Date()),query.detail.reqSeqID,outid});
                        }else {
                            detail.respCode="-1";
                            detail.respInfo = returnInfo;
                        }
                    }else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpsbMsg.toString();
                    }
                }else{
                    detail.respCode = "-1";
                    detail.respInfo = result[1];
                }
            }catch (Exception ex){
                ex.printStackTrace();
                detail.respCode = "-1";
                detail.respInfo =ex.getMessage();
            }finally {
                conn.close();
            }
            retAts.writeDetail(detail);
        }
        retAts.writeEnd();
        return retAts;
    }
//质押
    @Override
    public RetAtsB107BillPledSubmit D_B107_BillResp_Submit(ReqB107BillPledSubmit query) throws Exception {
        RetAtsB107BillPledSubmit retAts = new RetAtsB107BillPledSubmit(query.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        while (query.readRecord()){
            RetAtsB107BillPledSubmitDetail detail = new RetAtsB107BillPledSubmitDetail();
            try {
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
                LCBIP01Header header = new LCBIP01Header();
                header.TuxName = "BillPledgeApply";
                header.ReqSeqNo =query.detail.reqSeqID;
                writeCommonHeader(xmlTextWriter,header);
                xmlTextWriter.writeElementString("ReqReserved1","",true);
                xmlTextWriter.writeElementString("ReqReserved2","",true);
                xmlTextWriter.writeElementString("ReqReserved3","",true);
                xmlTextWriter.writeElementString("ReqReserved4","",true);
                xmlTextWriter.writeEndElement();
                xmlTextWriter.writeStartElement("body");
//                企业编号	CustCode	成员单位在内部ERP系统的客户编号
                xmlTextWriter.writeElementString("CustCode",bankFront.org);
//                机构名称	OrgName	默认写死：兵器装备集团财务有限责任公司
                xmlTextWriter.writeElementString("OrgName","兵器装备集团财务有限责任公司");
//                机构号	OrgNo	写死：99
                xmlTextWriter.writeElementString("OrgNo","99");
//                票据种类	BillType	票据种类:银行承兑汇票：“1”、商业承兑汇票：“2”
                xmlTextWriter.writeElementString("BillType",query.detail.billType);

//                质权行名称	PledgeBankName	Y	默认写死：兵器装备集团财务有限责任公司
                xmlTextWriter.writeElementString("PledgeBankName","兵器装备集团财务有限责任公司");
//                质权行编号	PledgeBank	Y	默认写死：99
                xmlTextWriter.writeElementString("PledgeBank","99");
//                质权行行号	PledgeBankNo	Y	默认写死：907100000255
                xmlTextWriter.writeElementString("PledgeBankNo","907100000255");
//                质权行账户	PledgeAcc	Y	默认写死：0
                xmlTextWriter.writeElementString("PledgeAcc","0");
//                库存票据编号	BillCodes	Y	需要质押的库存票据的编号，从收票信息中查询到的30位票据编号 可单张可多张票据，多张票据，票据编号以“|”分隔
                xmlTextWriter.writeElementString("BillCodes",query.detail.billNo);
//                来源模块	sourceModel	Y	来源模块：0 纸票、 1 电票
//                xmlTextWriter.writeElementString("BillCodes","1");
//                备注	Remark	N
                xmlTextWriter.writeElementString("Remark",query.detail.memo);
//                备用字段1	ReqReserved1 reqReserved1
                xmlTextWriter.writeElementString("ReqReserved1","",true);
//                备用字段2	ReqReserved2 reqReserved2
                xmlTextWriter.writeElementString("ReqReserved2","",true);
//                备用字段3	ReqReserved3 reqReserved3
                xmlTextWriter.writeElementString("ReqReserved3","",true);
//                备用字段4	ReqReserved4 reqReserved4
                xmlTextWriter.writeElementString("ReqReserved4","",true);
                xmlTextWriter.writeEndDocument();
                String[] result =sendToBank(xmlTextWriter.toXmlString());
                if(result[0].length()==0) {
                    StringBuilder tmpsbMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1],tmpsbMsg);
                    if(tmpbkReader!=null){
                        String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                        String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                        if("0".equals(returnCode)){
                            detail.respCode ="0";
                            detail.respInfo = tmpbkReader.getFirstText("/lcbank/body/BillPledAddRespParam/ErrorInfo");
                            detail.transState = tmpbkReader.getFirstText("/lcbank/body/BillPledAddRespParam/Result");
                            detail.payInfoCode = detail.transState;
                            String outid = tmpbkReader.getFirstText("/lcbank/body/BillPledAddRespParam/PledgeId");
                            String uuid = UUID.randomUUID().toString().replaceAll("-","");
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,Format.Date8Format.format(new Date()),query.detail.reqSeqID,outid});
                        }else {
                            detail.respCode="-1";
                            detail.respInfo = returnInfo;
                        }
                    }else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpsbMsg.toString();
                    }
                }else{
                    detail.respCode = "-1";
                    detail.respInfo = result[1];
                }
            }catch (Exception ex){
                ex.printStackTrace();
                detail.respCode = "-1";
                detail.respInfo =ex.getMessage();
            }finally {
                conn.close();
            }
            retAts.writeDetail(detail);
        }
        retAts.writeEnd();
        return retAts;
    }
//提示付款
    @Override
    public RetAtsB108BillPaySubmit D_B108_BillResp_Submit(ReqB108BillPaySubmit query) throws Exception {
//        BillPromptPayApply
        RetAtsB108BillPaySubmit retAts = new RetAtsB108BillPaySubmit(query.reqHeader);
        retAts.writeStart();
        Connection conn = FGBiz.getLocalDbConn();
        while (query.readRecord()){
            RetAtsB108BillPaySubmitDetail detail = new RetAtsB108BillPaySubmitDetail();
            try {
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
                LCBIP01Header header = new LCBIP01Header();
                header.TuxName = "BillPromptPayApply";
                header.ReqSeqNo =query.detail.reqSeqID;
                writeCommonHeader(xmlTextWriter,header);
                xmlTextWriter.writeElementString("ReqReserved1","",true);
                xmlTextWriter.writeElementString("ReqReserved2","",true);
                xmlTextWriter.writeElementString("ReqReserved3","",true);
                xmlTextWriter.writeElementString("ReqReserved4","",true);
                xmlTextWriter.writeEndElement();
                xmlTextWriter.writeStartElement("body");
//                企业编号	CustCode	成员单位在内部ERP系统的客户编号
                xmlTextWriter.writeElementString("CustCode",bankFront.org);
//                机构名称	OrgName	默认写死：兵器装备集团财务有限责任公司
                xmlTextWriter.writeElementString("OrgName","兵器装备集团财务有限责任公司");
//                机构号	OrgNo	写死：99
                xmlTextWriter.writeElementString("OrgNo","99");
//                票据种类	BillType	票据种类:银行承兑汇票：“1”、商业承兑汇票：“2”
                xmlTextWriter.writeElementString("BillType",query.detail.billType);
//                提示付款类型	PromptType	Y	20 正常提示付款;21 逾期提示付款
                String promptType;
                if("1".equals(query.detail.proPayType)){
                    promptType ="20";
                }else{
                    promptType = "21";
                }
                xmlTextWriter.writeElementString("promptType",promptType);
//                提示付款日期	PromptDate	Y	默认当前账务日期
                xmlTextWriter.writeElementString("PromptDate",Format.Date8Format.format(new Date()));
//                清算方式	CleanrMethod	Y	SM00-线上清算 SM01-线下清算
                String cleanrMethod;
                if("1".equals(query.detail.payType)){
//                    cleanrMethod = "SM00";
                    throw new Exception("暂不支持线上清算");
                }else {
                    cleanrMethod ="SM01";
                }
                xmlTextWriter.writeElementString("CleanrMethod",cleanrMethod);
//                逾期原因	OverdueReason	Y
                xmlTextWriter.writeElementString("OverdueReason",query.detail.overDueRea);
//                收款账户		Y
                xmlTextWriter.writeElementString("CollectBankAcc",query.detail.actNum);
//                收款账户名称 CollectAccname	Y
                xmlTextWriter.writeElementString("CollectAccname",query.detail.payeeName);
//                收款账户开户行	CollectBankName	Y
                xmlTextWriter.writeElementString("CollectBankName",query.detail.payeeBnkName);
//                收款账户开户行号	CollectBankNo	Y
                xmlTextWriter.writeElementString("CollectBankNo",query.detail.payeeBnkCode);
//                联系方式	PromptTel	N
                xmlTextWriter.writeElementString("PromptTel","",true);
//                票据编号	BillCodes	Y	提示付款的票据编号，30位票据号码，可单张可多张票据，多张票据，票据编号以“|”分隔
                xmlTextWriter.writeElementString("BillCodes",query.detail.billNo);
//                备注	Remark	N
                xmlTextWriter.writeElementString("Remark",query.detail.memo);
//                备用字段1	ReqReserved1 reqReserved1
                xmlTextWriter.writeElementString("ReqReserved1","",true);
//                备用字段2	ReqReserved2 reqReserved2
                xmlTextWriter.writeElementString("ReqReserved2","",true);
//                备用字段3	ReqReserved3 reqReserved3
                xmlTextWriter.writeElementString("ReqReserved3","",true);
//                备用字段4	ReqReserved4 reqReserved4
                xmlTextWriter.writeElementString("ReqReserved4","",true);
                xmlTextWriter.writeEndDocument();
                String[] result =sendToBank(xmlTextWriter.toXmlString());
                if(result[0].length()==0) {
                    StringBuilder tmpsbMsg = new StringBuilder();
                    XmlTextReader tmpbkReader = loadBankRespXmlReader(result[1],tmpsbMsg);
                    if(tmpbkReader!=null){
                        String returnCode = tmpbkReader.getFirstText("/lcbank/head/RespCode");
                        String returnInfo = tmpbkReader.getFirstText("/lcbank/head/RespInfo");
                        if("0".equals(returnCode)){
                            detail.respCode ="0";
                            detail.respInfo = tmpbkReader.getFirstText("/lcbank/body/BillPromptSubmitRespParam/ErrorInfo");
                            detail.transState = tmpbkReader.getFirstText("/lcbank/body/BillPromptSubmitRespParam/Result");
                            detail.payInfoCode = detail.transState;
                            String outid = tmpbkReader.getFirstText("/lcbank/body/BillPromptSubmitRespParam/EndorseId");
                            String uuid = UUID.randomUUID().toString().replaceAll("-","");
                            JDBCHelper.update(conn,INSERTRECEIPT,new Object[]{uuid,query.reqHeader.bankCode,Format.Date8Format.format(new Date()),query.detail.reqSeqID,outid});
                        }else {
                            detail.respCode="-1";
                            detail.respInfo = returnInfo;
                        }
                    }else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpsbMsg.toString();
                    }
                }else{
                    detail.respCode = "-1";
                    detail.respInfo = result[1];
                }
            }catch (Exception ex){
                ex.printStackTrace();
                detail.respCode = "-1";
                detail.respInfo =ex.getMessage();
            }finally {
                conn.close();
            }
            retAts.writeDetail(detail);
        }
        retAts.writeEnd();
        return retAts;
    }
    //提示保证
    @Override
    public RetAtsB109BillGuarSubmit D_B109_BillResp_Submit(ReqB109BillGuarSubmit query) throws Exception {
        return null;
    }
//追索通知
    @Override
    public RetAtsB110BillRecoSubmit D_B110_BillResp_Submit(ReqB110BillRecoSubmit query) throws Exception {
        return null;
    }
//同意清偿
    @Override
    public RetAtsB111BillAgreeSubmit D_B111_BillResp_Submit(ReqB111BillAgreeSubmit query) throws Exception {
        return null;
    }
//交易撤回
    @Override
    public RetAtsB112BillCancSubmit D_B112_BillResp_Submit(ReqB112BillCancSubmit query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB113ProtocolSubmit D_B113_ProtocolResp_Submit(ReqB113ProtocolSubmit query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB119BillRelePledSubmit D_B119_BillResp_Submit(ReqB119BillRelePledSubmit query) throws Exception {
        return null;
    }
}
